package com.basic;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.ConvertUtils;

import com.business.socialcredit.SocialCreditFactory;
import com.frame.struts.ActionContext;
import com.frame.struts.BaseBean;
import com.utils.CommUtil;
import com.utils.DateConverter;

public class SpaqrzForm extends BaseBean
{
    public SpaqrzForm()
    {
    }
    
    static{
        ConvertUtils.register(new DateConverter(), Date.class);
    }

    SpaqrzEntity spaqrzEntity = new SpaqrzEntity();
    private String oldId="";

    public String addSpaqrz()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addSpaqrz()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        PublicInfoFactory factory = PublicInfoFactory.getInstance();
        String qyid = (String) request.getSession()
                                      .getAttribute( "session_qyid" );
        spaqrzEntity.setQyid( qyid );
        spaqrzEntity.setOptdate( new Date() );
        spaqrzEntity.setOptrid( CommUtil.getUserId( request ) );
        spaqrzEntity.setXh( SocialCreditFactory.getNextXh( "qy_spaqrz", qyid ) );
        try
        {
            if( factory.addSpaqrz( spaqrzEntity ) )
            {
                System.out.println( "Enter addSpaqrz()" );
                response.sendRedirect( "/publicinfo/queryspaqrz.jsp" );
            }else{
                response.sendRedirect( "/failed.jsp" );
            }
        }
        catch( Exception e )
        {
        }
        return null;

    }

    public String editSpaqrz()
    {
        if( logger.isDebugEnabled() )
        {
            logger.debug( "enter addSpaqrz()" );
        }
        HttpServletRequest request = ActionContext.getActionContext()
                                                  .getRequest();
        HttpServletResponse response = ActionContext.getActionContext()
                                                    .getResponse();
        PublicInfoFactory factory = PublicInfoFactory.getInstance();
        String qyid = (String) request.getSession()
                                      .getAttribute( "session_qyid" );
        spaqrzEntity.setQyid( qyid );
        spaqrzEntity.setOptdate( new Date() );
        spaqrzEntity.setOptrid( CommUtil.getUserId( request ) );
        factory.delSpaqrz(qyid,spaqrzEntity.getXh());
        try
        {
            if( factory.addSpaqrz( spaqrzEntity ) )
            {
                System.out.println( "Enter editSpaqrz()" );
                response.sendRedirect( "/publicinfo/queryspaqrz.jsp" );
            }else{
                response.sendRedirect( "/failed.jsp" );
            }
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return null;
    }
    
    public String getOldId(){
        return this.oldId;
    }
    public void setOldId(String oldId){
        this.oldId=oldId;
    }
    
    public String getQyid()
    {
        return spaqrzEntity.getQyid();
    }

    public void setQyid( String qyid )
    {
        spaqrzEntity.setQyid(qyid);
    }

    public int getXh()
    {
        return spaqrzEntity.getXh();
    }

    public void setXh( int xh )
    {
        spaqrzEntity.setXh( xh );
    }

    
    public String getOptrid()
    {
        return spaqrzEntity.getOptrid();
    }

    public void setOptrid( String optrid )
    {
        spaqrzEntity.setOptrid( optrid );
    }

    public Date getOptdate()
    {
        return spaqrzEntity.getOptdate();
    }

    public void setOptdate( Date optdate )
    {
        spaqrzEntity.setOptdate( optdate );
    }

    public String getRecstate()
    {
        return spaqrzEntity.getRecstate();
    }

    public void setRecstate( String recstate )
    {
        spaqrzEntity.setRecstate( recstate );
    }

    public String getRemark()
    {
        return spaqrzEntity.getRemark();
    }

    public void setRemark( String remark )
    {
        spaqrzEntity.setRemark( remark );
    }
    
    public String getRzjg()
    {
        return spaqrzEntity.getRzjg();
    }
    public void setRzjg( String rzjg )
    {
        spaqrzEntity.setRzjg( rzjg );
    }
    public String getSyfw()
    {
        return spaqrzEntity.getSyfw();
    }
    public void setSyfw( String syfw )
    {
        spaqrzEntity.setSyfw( syfw );
    }
    public String getYxq()
    {
        return spaqrzEntity.getYxq();
    }
    public void setYxq( String yxq )
    {
        spaqrzEntity.setYxq( yxq );
    }
    
    public String getRzbz()
    {
        return spaqrzEntity.getRzbz();
    }
    public void setRzbz( String rzbz )
    {
        spaqrzEntity.setRzbz( rzbz );
    }
    
    public String getZsbh()
    {
        return spaqrzEntity.getZsbh();
    }
    public void setZsbh( String zsbh )
    {
        spaqrzEntity.setZsbh( zsbh );
    }
}
